package com.itHaipeng.service.impl;

import com.itHaipeng.dao.IDaoAccount;
import com.itHaipeng.pojo.Account;
import com.itHaipeng.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service(value = "iAccountServiceImpl")
public class IAccountServiceImpl implements IAccountService {
    @Autowired
    private IDaoAccount iDaoAccount;
    @Override
    public List<Account> selectAll() {
        return iDaoAccount.queryAll();
    }

    @Override
    public Account selectByName(String name) {
        return iDaoAccount.findByName(name);
    }

    @Override
    public void upData(Account account) {
        iDaoAccount.upData(account);
    }
    /**
     *
     * @param targetName :转入账户
     * @param primaryName ：转出账户
     * @param money ：多少钱
     */
    @Override
    public void transfer(String targetName, String primaryName, float money) {
        Account byName = iDaoAccount.findByName(targetName);
        Account byName1 = iDaoAccount.findByName(primaryName);
        byName1.setMoney(byName1.getMoney()-money);
        byName.setMoney(byName.getMoney()+money);
        iDaoAccount.upData(byName);
        iDaoAccount.upData(byName1);
    }
}
